home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / Menu Fixer 1.0 Source / Menu fixer ƒ / MSG Shell ƒ / msg menus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-15  |  2.7 KB  |  138 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        msg menus.c
  4.  
  5. Purpose:    This module handles menu selections.
  6.  
  7.  
  8. Menu Fixer -=- synchronize menu IDs and menu resource IDs
  9. Copyright (C) 1993 Mark Pilgrim
  10.  
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program in a file named "GNU General Public License".
  23. If not, write to the Free Software Foundation, 675 Mass Ave,
  24. Cambridge, MA 02139, USA.
  25.  
  26. \**********************************************************************/
  27.  
  28. #include "msg graphics.h"
  29. #include "msg menus.h"
  30. #include "msg environment.h"
  31. #include "fix.h"
  32. #include "fix meat.h"
  33.  
  34. MenuHandle        gAppleMenu;
  35. MenuHandle        gFileMenu;
  36. MenuHandle        gEditMenu;
  37. MenuHandle        gHelpMenu;
  38.  
  39. void AdjustMenus(void)
  40. {
  41.     WindowPeek    theWindow;
  42.     int            kind;
  43.     int            i;
  44.     
  45.     theWindow = (WindowPeek)FrontWindow();
  46.     kind = theWindow ? theWindow->windowKind : 0;
  47.     
  48.     if(kind < 0)
  49.         EnableItem(gEditMenu, 0);
  50.     else
  51.         DisableItem(gEditMenu, 0);
  52.     
  53.     if(theWindow)
  54.         EnableItem(gFileMenu, closeItem);
  55.     else
  56.         DisableItem(gFileMenu, closeItem);
  57. }
  58.  
  59. void HandleMenu(long mSelect)
  60. {
  61.     int            menuID = HiWord(mSelect);
  62.     int            menuItem = LoWord(mSelect);
  63.     
  64.     switch (menuID)
  65.     {
  66.         case appleMenu:
  67.             HandleAppleMenu(menuItem);
  68.             break;
  69.         case fileMenu:
  70.             HandleFileMenu(menuItem);
  71.             break;    
  72.         case editMenu:
  73.             HandleEditMenu(menuItem);
  74.             break;
  75.         case helpMenu:
  76.             HandleHelpMenu(menuItem);
  77.             break;
  78.       }
  79. }
  80.  
  81. void HandleAppleMenu(int menuItem)
  82. {
  83.     GrafPtr        savePort;
  84.     Str255        name;
  85.     
  86.     if(menuItem == 1)
  87.         ShowInformation();
  88.     else if(menuItem > 3)
  89.     {
  90.         GetPort(&savePort);
  91.         GetItem(gAppleMenu, menuItem, name);
  92.         OpenDeskAcc(name);
  93.         SetPort(savePort);
  94.     }
  95. }
  96.  
  97. void HandleFileMenu(int menuItem)
  98. {
  99.     Point            where;
  100.     SFTypeList        typeList;
  101.     WindowPtr        theWindow;
  102.     int                i;
  103.     
  104.     switch (menuItem)
  105.     {
  106.         case openItem:
  107.             OpenTheFile();
  108.             break;
  109.         case closeItem:
  110.             theWindow=FrontWindow();
  111.             for (i=0; i<NUM_HELP; i++)
  112.                 if (theWindow == gHelp[i])
  113.                     gHelp[i]=0L;
  114.             DisposeWindow(theWindow);
  115.             AdjustMenus();
  116.             break;
  117.         case quitItem:
  118.             gDone = TRUE;
  119.             break;
  120.     }
  121. }
  122.  
  123. void HandleEditMenu(int menuItem)
  124. {
  125.     SystemEdit(menuItem-1);
  126. }
  127.  
  128. void HandleHelpMenu(int menuItem)
  129. {
  130.     int            prefsFileID;
  131.     
  132.     if ((menuItem>0) && (menuItem<=NUM_HELP))
  133.     {
  134.         OpenHelpWindow(menuItem-1);
  135.         SelectWindow(gHelp[menuItem-1]);
  136.     }
  137. }
  138.